<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>电梯信息维护</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<link rel="stylesheet" type="text/css" href="../../css/style.css">
	<script type="text/javascript" src="../../js/jquery-1.8.2.js"></script>
	<script type="text/javascript" src="../../js/dialog/jquery.artDialog.source.js?skin=default"></script>
	<script type="text/javascript" src="../../js/dialog/plugins/iframeTools.source.js"></script>
	<script type="text/javascript" src="http://api.map.baidu.com/api?v=1.3"></script>
	<script type="text/javascript" src="../../js/jquery.ztree.all-3.5.min.js"></script>
	<script type="text/javascript" src="../../js/datepicker/WdatePicker.js"></script>
	<script type="text/javascript" src="../../js/jquery.form.js"></script>
	<script type="text/javascript" src="../../js/jquery.page.js"></script>
	<script type="text/javascript" src="../../js/base.js"></script>
	<style type="text/css">
		.anchorBL{display:none;}
		.BMap_bubble_content p{clear:both;}
		.BMap_bubble_content p label{display:block;float:left;width:70px;text-align:left;}
		.BMap_bubble_content p span{display:block;float:left;}
	</style>
</head>
<body class="app">
	<h3>电梯信息维护</h3>
	<form class="search" name="search">
		<div class="tbdiv">
		<table>
			<tr>
				<th width="94">行政监管单位：</th>
				<td width="111"><select name="adminCode"></select></td>
				<th width="94">物业公司：</th>
				<td width="111"><select name="propertyCode"></select></td>
				<th width="94">维保单位：</th>
				<td><select name="serviceCode"></select></td>
			</tr>
			<tr>
				<th width="94">电梯名称：</th>
				<td width="111"><input type="text" class="inputText" name="eleName" value="" style="width:110px;"/></td>
				<th width="94">电梯编号：</th>
				<td width="111"><input type="text" class="inputText" name="eleCode" value="" style="width:110px;"/></td>
				<th width="94">审核状态：</th>
				<td>
					<select name="checkStatus">
						<option value="">-请选择-</option>
						<option value="0">待审核</option>
						<option value="1">已通过</option>
						<option value="2">未通过</option>
					</select>
				</td>
			</tr>
			<tr>
				<td colspan="6">
					<table>
						<tr>
							<th>所属区域：</th>
							<td colspan="4">
								<input type="hidden" name="areaName" value=""/>
								<input type="text" class="inputText" name="areaNameN" value="" style="width:347px;*width:348px;cursor:pointer;" readonly="readonly" />
							</td>
							<td><input type="submit" value="查询" class="inputButton"/></td>
						</tr>
					</table>
				</td>
			</tr>
		</table>
		</div>
	</form>
	<div class="areaTree"><div id="areaTree" class="ztree"></div></div>
	
	<div id="mapd" style="display:none;">
		<form method="post" name="mps" id="mps">
		<table width="100%">
			<tr>
				<td>
					<input type="text" id="mkey" class="inputText" style="width:99%"/>
				</td>
				<td align="right" width="100">
					<input type="submit" value="搜索" id="msbtn"/>
				</td>
			</tr>
		</table>
		</form>
		<div id="container" style="width:560px;height:320px;"></div>
	</div>
	<div id="list"></div>
	<div class="optionlink">
		<span id="btnAdd">【添加信息】</span>
		<span id="btnDel">【删除所选】</span>
	</div>
	<div id="view" style="width:650px;display:none;">
		<form name="saveFrom" action="jbxxwh_save.action" method="post">
		<input type="hidden" name="eleBasicId" />
			<input type="hidden"  name="checkStatus" />
			<input type="hidden"  name="floorName" />
		<dl class="view">
			<dt>电梯号码：</dt>
			<dd id="lh_eleCode"><input type="text" class="inputText" style="width:95%" name="eleCode" value="T" ver="/^[tT][0-9a-fA-F]{6,6}$/" msg="您输入的电梯编号不合法。" /></dd>
			<dt>电梯名称：</dt>
			<dd><input type="text" class="inputText" style="width:95%" name="eleName" /></dd>
			<dt>注册代码：</dt>
			<dd><input type="text" class="inputText" style="width:95%" name="eleBasicRegNum" /></dd>
			<dt>电梯型号：</dt>
			<dd><input type="text" class="inputText" style="width:95%" name="eleBasicType" /></dd>
			<dt>电梯类型：</dt>
			<dd><select name="eleBasicStyle" class="inputText" style="width:156px;padding:2px;"></select></dd>
			<dt>电梯品牌：</dt>
			<dd><select name="eleBasicTrade" class="inputText" style="width:156px;padding:2px;" ></select></dd>
			<dt>出场日期：</dt>
			<dd><input type="text" class="inputText Wdate" onfocus="WdatePicker({maxDate:'%y-%M-{%d}'})" style="width:154px;padding:0px;" readonly="readonly" name="leaveFactoryDate"/></dd>
			<dt>额定速度：</dt>
			<dd><input type="text" class="inputText" style="width:95%" name="ratingRate" ver="empty" msg="请输入额定速度" onchange="formatnum(this)" /></dd>
			<dt>额定载重：</dt>
			<dd><input type="text" class="inputText" style="width:95%" name="ratingLoad" /></dd>
			<dt>曳引机：</dt>
			<dd><input type="text" class="inputText" style="width:95%" name="towEngine" /></dd>
			<dt>控制系统：</dt>
			<dd><input type="text" class="inputText" style="width:95%" name="controlSystem" /></dd>
			<dt>变频器：</dt>
			<dd><input type="text" class="inputText" style="width:95%" name="freConversion" /></dd>
			<dt>安全钳：</dt>
			<dd><input type="text" class="inputText" style="width:95%" name="safetyClamp" /></dd>
			<dt>限速器：</dt>
			<dd><input type="text" class="inputText" style="width:95%" name="limitToImplement" /></dd>
			<dt>限速器直径：</dt>
			<dd><input type="text" class="inputText" style="width:95%" name="limitToImpDia" /></dd>
			<dt>制造单位：</dt>
			<dd><input type="text" class="inputText" style="width:95%" name="produceUnit" /></dd>
			<dt>安装时间：</dt>
			<dd><input type="text" class="inputText Wdate" onfocus="WdatePicker({maxDate:'%y-%M-{%d}'})" style="width:154px;padding:0px;" readonly="readonly" name="eleSetDate" /></dd>
			<dt>是否节能：</dt>
			<dd><select name="energyStatus" class="inputText" style="width:156px;padding:2px;"></select></dd>
			<dt>电梯顶层：</dt>
			<dd><input type="text" class="inputText" style="width:95%" name="eleTopFloor" /></dd>
			<dt>电梯底层：</dt>
			<dd><input type="text" class="inputText" style="width:95%" name="eleGroundFloor" /></dd>
			<dt>SIM卡号：</dt>
			<dd><input type="text" class="inputText" style="width:95%" name="simCard" /></dd>
			<dt>电梯总楼层：</dt>
			<dd>
				<input type="text" class="inputText" style="width:60px" name="eleFloor" />
				<a href="javascript:void(0)" onclick="setfname(this)">楼层名称</a>
			</dd>
			<dt>电梯额定运行次数：</dt>
			<dd><input type="text" class="inputText" style="width:95%" name="eleSumTime" ver="/^\d*$/" msg="电梯额定运行次数必须为正整数" /></dd>
			<dt>电梯初始运行次数：</dt>
			<dd><input type="text" class="inputText" style="width:95%" name="eleCirculateTime" ver="/^\d*$/" msg="电梯初始运行次数必须为正整数" /></dd>
			<dt>门机额定运行次数：</dt>
			<dd><input type="text" class="inputText" style="width:95%" name="doorSumTime" ver="/^\d*$/" msg="门机额定运行次数必须为正整数" /></dd>
			<dt>门机初始运行次数：</dt>
			<dd><input type="text" class="inputText" style="width:95%" name="doorCirculateTime" ver="/^\d*$/" msg="门机初始运行次数必须为正整数"/></dd>
			<dt>制动器额定运行次数：</dt>
			<dd><input type="text" class="inputText" style="width:95%" name="detentSumTime" ver="/^\d*$/" msg="制动器额定运行次数必须为正整数"/></dd>
			<dt>制动器初始运行次数：</dt>
			<dd><input type="text" class="inputText" style="width:95%" name="detentCirculateTime" ver="/^\d*$/" msg="制动器初始运行次数必须为正整数"/></dd>
			<dt>主接触器额定运行次数：</dt>
			<dd><input type="text" class="inputText" style="width:95%" name="mainContactSumTime" ver="/^\d*$/" msg="主接触器额定运行次数必须为正整数"/></dd>
			<dt>主接触器初始运行次数：</dt>
			<dd><input type="text" class="inputText" style="width:95%" name="mainContactCirTime" ver="/^\d*$/" msg="主接触器初始运行次数必须为正整数"/></dd>
			<dt>辅助接触器额定运行次数：</dt>
			<dd><input type="text" class="inputText" style="width:95%" name="runContactSumTime" ver="/^\d*$/" msg="辅助接触器额定运行次数必须为正整数"/></dd>
			<dt>辅助接触器初始运行次数：</dt>
			<dd><input type="text" class="inputText" style="width:95%" name="runContactCirTime" ver="/^\d*$/" msg="辅助接触器初始运行次数必须为正整数"/></dd>
			<dt>钢丝绳额定折弯次数：</dt>
			<dd><input type="text" class="inputText" style="width:95%" name="wireBendSumTime" ver="/^\d*$/" msg="钢丝绳额定折弯次数必须为正整数"/></dd>
			<dt>钢丝绳初始折弯次数：</dt>
			<dd><input type="text" class="inputText" style="width:95%" name="wireBendCirTime" ver="/^\d*$/" msg="钢丝绳初始折弯次数必须为正整数"/></dd>
			<dt>电梯经度：</dt>
			<dd><input type="text" class="inputText" style="width:95%" name="eleLongitude" readonly="readonly" /></dd>
			<dt>电梯纬度：</dt>
			<dd><input type="text" class="inputText" style="width:95%" name="eleLatitude" readonly="readonly" /></dd>
			<div class="cl"></div>
		</dl>
		</form>
	</div>
	<script type="text/javascript">
	var vCode = function(obj){
		var ver = $(obj).attr('ver');
		var msg = $(obj).attr('msg');
		var val = $(obj).val();
		var code = ver.substr(1);
			code = code.substr(0,code.length-1);
		var exp = new RegExp(code);
		if($.type(exp) === 'regexp'){
			if(!exp.test(val)){
				$.dialog.alert(msg);
				$(obj).focus();
				$(obj).val('T');
			}
		}
	}
	
	var setfname = function(obj){
		var $input = $(obj).prev('input');
		var $floorName = $(document.saveFrom.floorName);
		var fName = $floorName.val();
		var $table = $('<table></table>');
		var fNameArr = fName.split(' ');
		for(var i=1;i<=$input.val();i++){
		var fnv = '';
			if(fNameArr[i-1]!='undefined' && fNameArr[i-1]!=undefined && fNameArr[i-1]!=null)
				fnv = fNameArr[i-1]
			$table.append('<tr><td align="right" width="20" style="padding-right:5px">'+i+'</td><td><input type="text" class="inputText" name="fnames" value="'+fnv+'"/></td></tr>');
		}
		$.dialog({
			id:'fnameview',
			title:'设置楼层名称',
			lock:true,
			padding:'5px 8px 5px 5px',
			content:$table[0],
			button:[{
				name:'确定',
				focus:true,
				callback:function(){
					var $inputs = $table.find('input');
					var tmpArr = new Array();
					$.each($inputs,function(i,n){
						tmpArr.push($(n).val());
					});
					$floorName.val(tmpArr.join(' '));
				}
			}]
		});
	}
	function formatnum(obj){
		var num = $(obj).val();
		if($.isNumeric(num)){
			num = parseFloat(num);
			if(num >0 && num < 100){
				$(obj).val(num.toFixed(2));
			}else{
				$.dialog.alert('值必须为0至100以内的数字！',function(){
					$(obj).val('');
					$(obj).focus();
				});
			}
		}else{
			$.dialog.alert('请输入有效数字！',function(){
				$(obj).val('');
				$(obj).focus();
			});
		}
	}
	$(function(){
		$(document.search).ajaxForm({
			beforeSubmit:function(formData){
				var param = $(formData).formParam();
				$('#list').page('param',param);
				$('#list').page('show');
				return false;
			}
		});
		$(document.saveFrom).ajaxForm({
			beforeSubmit:function(formData){
				var ver = $(document.saveFrom).validator();
				if(!ver.reg) $.dialog.alert(ver.msg);
				return ver.reg;
			},
			success:function(response){
				var param = $(document.search).formParam();
				$('#list').page('param',param);
				$('#list').page('show');
				$.dialog.list['viewdialog'].close();
			}
		});
		//分页列表
		$('#list').page({
			url:'jbxxwh_search.action',
			config:'pageinfo,record,first,last,next,prev,jump',
			items:[{
				name:'eleBasicId',
				type:'checkbox',
				width:13
			},{
				title:'电梯号码',
				name:'eleCode'
			},{
				title:'电梯名称',
				name:'eleName'
			},{
				title:'电梯类型',
				name:'eleBasicStyleText'
			},{
				title:'电梯总楼层',
				name:'eleFloor'
			},{
				title:'安装时间',
				name:'eleSetDate'
			},{
				title:'审核状态',
				name:'checkStatus',
				irender:function(row){
					if(row.checkStatus == '0') return '待审核';
					if(row.checkStatus == '1') return '已通过';
					if(row.checkStatus == '2') return '未通过';
				}
			},{
				title:'详情',
				render:function(row){
					$a = $('<a href="javascript:void(0)")">【详细】</a>');
					$reason = $('<a href="javascript:void(0)">【理由】</a>');
					$a.click(function(){
						view(row);
					});
					$reason.click(function(){
						$.dialog.alert(row.reason);
					});
					if(row.checkStatus == '2'){
						$a.after($reason);
					}
					return $a;
				}
			}]
		});
		$('#btnAdd').click(function(){
			view(null);
		});
		$('#btnDel').click(function(){
			$.dialog.confirm('您确认删除所选电梯吗？',function(){
				var ids = $('#list').data('checked').join(',');
				$.post('jbxxwh_del.action',{ids:ids},function(response){
					$('#list').page('show',1);
				});
			});
		});
	});

	$(function(){
		$('#mps').ajaxForm({
			beforeSubmit:function(d){
				var mkw = $('#mkey').val();
				var local = new BMap.LocalSearch(map, {
					renderOptions:{map: map}
				});
				local.search(mkw);
				return false;
			}
		})
		
		//区域树
		//渲染区域树
		$.fn.zTree.init($('#areaTree'),{
			data: {
				key:{
					name:'areaname'
				},
				simpleData: {
					enable: true,
					idKey:'areacode',
					pIdKey:'parentcode',
					rootPId:0
				}
			},
			async: {
				enable: true,
				url:"../../common/area_tree.action",
				autoParam:["areacode"]
			},
			callback:{
				onClick:function(e,id,node){
					if(node.isParent == false){
						$('input[name=areaName]').val(node.areacode);
						var $areaTree = $('.areaTree');
						var areaArr = new Array();
						areaArr.unshift(node.areaname);
						while(node.parentcode > 0){
							node = node.getParentNode();
							areaArr.unshift(node.areaname);
						}
						$('input[name=areaNameN]').val(areaArr.join(' > '));
						$areaTree.hide();
					}
				}
			}
		});
		$('input[name=areaNameN]').click(function(){
			$this = $(this);
			$hidden = $('input[name=areaName]');
			$areaTree = $('.areaTree');
			$this.val('');
			$hidden.val('');
			var os = $this.offset();
			$areaTree.css({left:os.left,top:os.top+($this.outerHeight(true)-1)});
			$areaTree.show();
		});
		$(document).mouseup(function(e){
			var $target = $(e.target);
			if(!$target.is('.areaTree')){
				if($target.parents('.areaTree').length == 0){
					$('.areaTree').hide();
				}
			}
		});
		//区域树结束
		
		
		//绑定行政监管单位
		$('select[name=energyStatus]').selectload('../../common/code.action','code','codedesc',{codepid:'23'});
		$('select[name=eleBasicStyle]').selectload('../../common/code.action','code','codedesc',{codepid:'39'});
		$('select[name=adminCode]').selectload('../../common/adminunit_select.action','adminCode','adminName');
		$('select[name=propertyCode]').selectload('../../common/propertyunit_select.action','propertyCode','propertyName');
		$('select[name=serviceCode]').selectload('../../common/serviceunit_select.action','serviceCode','serviceName');
		$('select[name=eleBasicTrade]').selectload('../../common/eletm_select.action','eleTradeCode','eleTradeName');
	})
	
	try {
		var point = new BMap.Point(116.404,39.915);	//北京天安门坐标
		var geolocation = new BMap.Geolocation();
		
		var map = new BMap.Map('container');
		map.enableScrollWheelZoom();
		map.enableContinuousZoom();
		map.addControl(new BMap.MapTypeControl({mapTypes: [BMAP_NORMAL_MAP,BMAP_HYBRID_MAP]}));	//地图类型
		geolocation.getCurrentPosition(function(r){
			if(this.getStatus() == BMAP_STATUS_SUCCESS){
				point = r.point;
				map.panTo(point);
			}
			map.centerAndZoom(point, 20);
			
		});
		
	} catch (e) {
		// TODO: handle exception
	}
	var view = function(row){
		$(document.saveFrom).resetForm();
		$(document.saveFrom.eleBasicId).val('');
		var d = $.dialog({
			id:'viewdialog',
			title:'电梯信息维护',
			lock:true,
			padding:'5px 8px 5px 5px',
			width:'100%',
			height:'100%',
			content:document.getElementById('view'),
			button:[{
				name:'选择电梯坐标',
				callback:function(){
					try {
						var marker = new BMap.Marker();		//标注
						marker.enableDragging();
						map.clearOverlays();
						map.addEventListener("click",function(e){
							marker.setPosition(e.point)
							map.clearOverlays();
							map.addOverlay(marker);
						});
						if($(document.saveFrom.eleLongitude).val()!='' && $(document.saveFrom.eleLatitude).val()!=''){
							map.clearOverlays();
							map.setZoom(20);
							marker.setPosition(new BMap.Point($(document.saveFrom.eleLongitude).val(),$(document.saveFrom.eleLatitude).val()));
							map.panTo(new BMap.Point($(document.saveFrom.eleLongitude).val(),$(document.saveFrom.eleLatitude).val()));
							map.addOverlay(marker);
							map.addOverlay(marker);
							map.panBy(280,160);
						}else{
						}
						
						$.dialog({
							id:'locationdialog',
							title:'电梯地理位置',
							lock:true,
							padding:'0px 0px',
							content:document.getElementById('mapd'),
							close:function(){
								map.clearOverlays();
							},
							button:[{
								name:'确定',
								focus: true,
								callback:function(){
									var p = marker.getPosition();
									$(document.saveFrom.eleLongitude).val(p.lng);
									$(document.saveFrom.eleLatitude).val(p.lat);
								}
							}]
						});
					} catch (e) {
						alert('没有连接互联网');
					}
					return false;
				}
			}]
		});
		if(row == null || row.userId == '${userinfo.userId}'){
			d.button({
				name:"保存",
				focus:true,
				callback:function(){
					$(document.saveFrom).submit();
					return false;
				}
			});
		}
		
		if(row != null){
			$('#lh_eleCode').html('<label name="eleCode"></label><input type="hidden" name="eleCode"/>');
		}else{
			$('#lh_eleCode').html('<input type="text" class="inputText" style="width:95%" name="eleCode" value="T" ver="/^[tT][0-9a-fA-F]{6,6}$/" msg="您输入的电梯编号不合法。" onchange="vCode(this)" />');
		}
		$(document.saveFrom).json2form(row);
	}
	</script>
</body>
</html>
